package com.longqinuo.mycarservice.adapter;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longqinuo.mycarservice.R;
import com.longqinuo.mycarservice.entity.NearClearStation;

import java.util.List;


/**
 * Created by zxw on 2016/5/24.
 */
public class NearClearStationAdapter extends RecyclerView.Adapter<NearClearStationAdapter.MyViewHolder>{
    private List<NearClearStation> mList;
    private int itemLayout;
    private OnItemClickListener onItemClickListener;
    private LayoutInflater mInflater;
    public NearClearStationAdapter(List<NearClearStation> mList, int itemLayout, LayoutInflater inflater) {
        this.mList = mList;
        this.itemLayout = itemLayout;
        this.mInflater = inflater;
    }
    public interface OnItemClickListener {
        void onItemClick(View itemView, int position);
    }
    public void setOnItemClickListener (OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(itemLayout,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.name.setText(mList.get(position).getName());
        holder.distance.setText(mList.get(position).getDistace());
        holder.locale.setText(mList.get(position).getLocale());
        if (onItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(holder.itemView,position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);
            this.name = (TextView) itemView.findViewById(R.id.tv_name_near_clear);
            this.distance = (TextView) itemView.findViewById(R.id.tv_distance_near_clear);
            this.locale = (TextView) itemView.findViewById(R.id.tv_locale_near_clear);
        }

        public TextView name;
        public TextView distance;
        public TextView locale;

    }
}

